package com.hex.ds.hdrs.engine.service;

import com.hex.ds.hdrs.center.service.CenterManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class GrabDbExecService {

    @Autowired
    private CenterManager centerManager;

    @Value("${scheduled.center.grabFixedDelay}")
    private int grabFixedDelay;

    /*
     * @Method: grabDbExec <br>
     * @Param: [] <br>
     * @Return: void <br>
     * @Description：抢占中心任务-不能使用定时任务<br>
     * @Author： wz.li<br>
     * @Date： 2023/7/31 17:18 <br>
     * @Version： V2.0.2<br>
     */
    @Async
    public void grabDbExec() {
        while (true) {
            try {
                centerManager.grabDb();
                Thread.sleep(grabFixedDelay);
            } catch (Exception e) {
                log.error("抢占中心任务异常: {}", e.getMessage(), e);
            }
        }
    }
}
